﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Movement_Trajectory_Analysis
{
    public partial class OptionsForm : Form
    {
        MainForm mainForm;
        public OptionsForm(MainForm mainForm)
        {
            this.mainForm = mainForm;
            InitializeComponent();
        }

        private void trackBarAnalyse_Scroll(object sender, EventArgs e)
        {
            labelAnalyseMargin.Text = "Analyse margin: " + trackBarAnalyseMargin.Value.ToString();
        }

        private void trackBarColorTolerance_Scroll(object sender, EventArgs e)
        {
            labelColorTolerance.Text = "Color tolerance: " + trackBarColorTolerance.Value.ToString();
        }

        private void buttonSetDefault_Click(object sender, EventArgs e)
        {
            labelAnalyseMargin.Text = "Analyse margin: 5";
            trackBarAnalyseMargin.Value = 5;

            labelColorTolerance.Text = "Color tolerance: 30";
            trackBarAnalyseMargin.Value = 30;

            textBoxThreadSleep.Text = "24";
        }

        private void buttonSaveChanges_Click(object sender, EventArgs e)
        {
            mainForm.mta.tolerance = trackBarColorTolerance.Value;
            mainForm.mta.margin = trackBarAnalyseMargin.Value;
            mainForm.mta.threadSleep = Convert.ToInt32(textBoxThreadSleep.Text);
        }

        private void OptionsForm_Load(object sender, EventArgs e)
        {
            trackBarColorTolerance.Value = mainForm.mta.tolerance;
            labelColorTolerance.Text = "Color tolerance: " + mainForm.mta.tolerance;

            trackBarAnalyseMargin.Value = mainForm.mta.margin;
            labelAnalyseMargin.Text = "Analyse margin: "+ mainForm.mta.margin; 

            textBoxThreadSleep.Text = mainForm.mta.threadSleep.ToString();
        }

        private void textBoxThreadSleep_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != (char)Keys.Back)
            {
                e.Handled = true;
            }
        }
    }
}
